/*
 * @Author: biankai
 * @Date: 2021-11-04 14:27:50
 * @LastEditTime: 2021-11-10 10:31:48
 * @LastEditors: biankai
 * @FilePath: /gitee/devops_service/src/services/jenkins/view.service.ts
 */
import {
    Injectable,
    Inject,
    HttpService,
    BadRequestException,
} from '@nestjs/common';
import { BaseService } from './base.service';
@Injectable()
export class ViewService extends BaseService {

    constructor(@Inject(HttpService) private readonly httpService: HttpService) {
        super()
    }
    async viewList() {
        const resBody = await this.jenkinsObj.view.list()
        return await resBody;
    }

    async viewGet(viewName) {
        const resBody = await this.jenkinsObj.view.get(viewName,)
        return await resBody;
    }
    async viewConfig(viewName, configXml) {
        const resBody = await this.jenkinsObj.view.config(viewName, configXml)
        return await resBody;
    }
    async viewCreate(viewName, viewType) {
        if (!viewName) {
            throw new BadRequestException(`viewName  must be passed`);
        }
        if (!viewType) {
            throw new BadRequestException(`viewType  must be passed`);
        }
        const resBody = await this.jenkinsObj.view.create(viewName, viewType,)
        return await resBody;
    }
    async viewDestroy(viewName) {
        const resBody = await this.jenkinsObj.view.destroy(viewName,)
        return await resBody;
    }
    async viewExists(viewName) {
        const resBody = await this.jenkinsObj.view.exists(viewName,)
        return await resBody;
    }
    async viewAdd(viewName, jobName) {
        const resBody = await this.jenkinsObj.view.add(viewName, jobName,)
        return await resBody;
    }
    async viewRemove(viewName, jobName) {
        const resBody = await this.jenkinsObj.view.remove(viewName, jobName,)
        return await resBody;
    }
}
